﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OneShoppingDAL;
using OneShoppingModel;
using System.Linq.Expressions;
namespace OneShoppingBLL
{
    public class  RoleBLL
    {
        private static  RoleBLL instance;
        public static  RoleBLL GetInstance()
        {
            if (instance == null)
            {
                instance = new  RoleBLL();
            }
            return instance;
        }
        /// <summary>
        /// 根据Lambda表达式predicate条件，获取 Role 单一实体
        /// </summary>
        /// <param name="predicate">获取实体的条件</param>
        /// <returns> Role单一实体</returns>
        public Role GetEntity(Expression<Func<Role, bool>> predicate)
        {
            if (predicate != null)
                return LinqUtility.GetInstance().GetEntity<Role>
                    (new OneShoppingDataContext(),
                predicate);
            else return null;

        }
        /// <summary>
        /// 获取Role表的所有实体
        /// </summary>
        /// <returns>Role集合</returns>
        public List<Role> GetList()
        {
            return   LinqUtility.GetInstance().GetList<Role>
                    (new OneShoppingDataContext());
        }

        /// <summary>
        /// 根据Lambda表达式predicate条件，获取Role集合
        /// </summary>
        /// <param name="predicate">获取列表的条件</param>
        /// <returns>Role集合</returns>
        public List<Role> GetList(Expression<Func<Role, bool>> predicate)
        {
            if (predicate != null)
                return LinqUtility.GetInstance().GetList<Role>
                    (new OneShoppingDataContext(), predicate);
            else return null;
        }
        /// <summary>
        /// 根据Lambda表达式predicate条件、每页条数pageSize、页码pageIndex，获取Role集合
        /// </summary>
        /// <param name="predicate">获取列表的条件</param>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">页码</param>
        /// <returns>Role集合</returns>
        public List<Role> GetList(Expression<Func<Role, bool>> predicate,
           int pageSize, int pageIndex)
        {

            if (predicate != null)
            return LinqUtility.GetInstance().GetList<Role>
                (new OneShoppingDataContext(), predicate, pageSize, pageIndex);

             else return null;
        }
        /// <summary>
        /// 添加Role实体
        /// </summary>
        /// <param name="entity">Role实体</param>
        /// <returns>是否成功添加</returns>
        public bool Insert(Role entity)
        {
            return
                LinqUtility.GetInstance().InsertEntity<Role>(new OneShoppingDataContext(), entity);

        }
        /// <summary>
        /// 更新Role实体
        /// </summary>
        /// <param name="entity">Role实体</param>
        /// <returns>是否成功更新</returns>
        public bool Update(Role entity)
        {
            return
                LinqUtility.GetInstance().UpdateEntity<Role>(new OneShoppingDataContext(), entity);

        }
        /// <summary>
        ///删除某主键id的Role实体
        /// </summary>
        /// <param name="id">主键id</param>
        /// <returns>是否删除成功</returns>
        public bool Delete(int id)
        {

            return LinqUtility.GetInstance().DeleteEntity<Role>(new OneShoppingDataContext(),
                  k => k.RoleId == id);
        }

    }
}